package com.example;

import com.example.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        // 加载Spring配置文件，初始化容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 获取OrderService实例
        OrderService orderService = (OrderService) context.getBean("orderService");

        System.out.println("=== 测试add方法 ===");
        try {
            orderService.add("笔记本电脑", 1);
        } catch (Exception e) {
            System.out.println("捕获异常: " + e.getMessage());
        }

        System.out.println("\n=== 测试delete方法 ===");
        try {
            orderService.delete("手机");
        } catch (Exception e) {
            System.out.println("捕获异常: " + e.getMessage());
        }

        System.out.println("\n=== 测试find方法 ===");
        try {
            orderService.find("平板电脑");
        } catch (Exception e) {
            System.out.println("捕获异常: " + e.getMessage());
        }
    }
}
